import type { NextApiRequest, NextApiResponse } from "next";
import { readdirSync } from "fs";
import path from "path";
import os from "os";

type Data = {
  filenameList: string[];
};

export default function handler(
  req: NextApiRequest,
  res: NextApiResponse<Data>
) {
  const outputFilePath = path.join(
    os.userInfo().homedir,
    "stable-diffusion-webui/outputs/txt2img-images"
  );
  // console.log(outputFilePath);
  const resData: Data = {
    filenameList: readdirSync(outputFilePath).map((filename) => `${filename}`),
  };
  res.status(200).json(resData);
  // 返回网络地址
}
